package com.fangcun.controller.admin.old.agent;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fangcun.bean.sys.ResponseMsg;
import com.fangcun.common.canstant.ErrCode;
import com.fangcun.common.exception.ProRunTimeException;
import com.fangcun.common.util.PublicMethod;
import com.fangcun.common.util.apiversion.ApiVersion;
import com.fangcun.entity.AgentShareBenefitsRule;
import com.fangcun.service.admin.AgentShareBenefitsRuleService;

/**
 * @作者： 陳曉鬆 @时间： 2020年8月18日 - 上午10:11:24 @description：->
 */
@RestController
@RequestMapping("/admin/{version}/auth/agent/sharebenefils")
public class AgentShareBenefitsRuleController {

	private static Logger LOG = LoggerFactory.getLogger(AgentShareBenefitsRule.class);

	@Resource(name = "agentShareBenefitsRuleService")
	private AgentShareBenefitsRuleService agentShareBenefitsRuleService;

	@ApiVersion(1.0)
	@RequestMapping(value = "/detail")
	private ResponseMsg agentShareBenefitsRuleDetail(Long agentId) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(agentShareBenefitsRuleService.detail(agentId));
		} catch (ProRunTimeException e) {
			LOG.error("-代理商分利-详情出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-代理商分利-详情异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping(value = "/update")
	private ResponseMsg settingShareBenefits(@RequestBody AgentShareBenefitsRule request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			agentShareBenefitsRuleService.settingShareBenefits(request);
		} catch (ProRunTimeException e) {
			LOG.error("-代理商分利-修改出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-代理商分利-修改异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
